import Vue from 'vue';
import Router from 'vue-router';

// 懒加载导入各个页面组件
const Home = () => import('../views/Home.vue');
const Login = () => import('../views/Login.vue');
const Register = () => import('../views/Register.vue');
const Search = () => import('../views/Search.vue');
const SongDetail = () => import('../views/SongDetail.vue');

// 注册路由插件
Vue.use(Router);

// 创建路由实例并导出
export default new Router({
  mode: 'history', // 使用HTML5 History模式，去掉URL中的#
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/register',
      name: 'register',
      component: Register
    },
    {
      path: '/search',
      name: 'search',
      component: Search
    },
    {
      path: '/song/:id',
      name: 'songDetail',
      component: SongDetail
    },
    // 重定向其他路径到主页
    {
      path: '*',
      redirect: '/'
    }
  ]
});